package com.vhuomai.product.home.service.impl;

import com.quanyue.auto.util.GlobalContext;
import com.vhuomai.product.home.entity.BaseHomeCategory;
import com.vhuomai.product.home.mapper.HomeCategoryMapper;
import com.vhuomai.product.home.service.HomeCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class HomeCategoryServiceImpl implements HomeCategoryService {
    @Autowired
    private HomeCategoryMapper homeCategoryMapper;

    @Override
    public void createHomeCategory(BaseHomeCategory homeCategory) {
        homeCategory.setId(null);
        homeCategory.setMerchantNo(GlobalContext.merchantNo());
        homeCategory.setCreateTime(LocalDateTime.now());
        homeCategory.setUpdateTime(LocalDateTime.now());
        homeCategoryMapper.insert(homeCategory);
    }

    @Override
    public void updateHomeCategory(BaseHomeCategory homeCategory) {
        homeCategory.setUpdateTime(LocalDateTime.now());
        homeCategoryMapper.updateSelective(homeCategory);
    }

    @Override
    public void deleteHomeCategory(Integer id) {
        homeCategoryMapper.deleteOne(id);
    }

    @Override
    public List<BaseHomeCategory> findHomeCategoryList() {
        return homeCategoryMapper.findByMerchantNo(GlobalContext.merchantNo());
    }
}
